﻿ using System;
using System.Collections.Generic;
using System.Linq;
using Models;

public partial class index : AdminBase
{
    public string MYLeftMenu = "";
    public string mynewlist = "";
    public string admin_power = "", admin_Role = "";
    public string LoginName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        GetMenuString();
        LoginName = Session["AdminName"].ToString();
    }

    protected void GetMenuString()
    {
        Entities mydb = new Entities();

        List<LeftMenu> menus = LeftMenu.Load();
        int _Id = int.Parse(Session["AdminID"].ToString());
        string tt = "" + mydb.Manages.SingleOrDefault(p => p.MID == _Id).MPower;


       //string tt = Session["AdminType"].ToString();
        string[] sArray = tt.Split(',');
        List<int> menuNum = new List<int>();
        for (int i = 0; i < sArray.Length; i++)
        {
            if (sArray[i] != "")
            {
                int p = Convert.ToInt32(sArray[i]) / 100;
                if (menuNum != null)
                {
                    if (!menuNum.Contains(p))
                    {
                        menuNum.Add(p);
                    }
                }
                else
                {
                    menuNum.Add(p);
                }

            }

        }


        foreach (LeftMenu menu in menus)
        {
            Boolean b = false;
            for (int i = 0; i < menuNum.Count; i++)
            {

                if ((Convert.ToInt32(menu.Code) / 100) == menuNum[i])
                {
                    MYLeftMenu += string.Format("<li><a href='#'><i class='fa {0}'></i><span class='nav-label'>{1}</span><span class='fa arrow'></span></a><ul class='nav nav-second-level'>", menu.Img, menu.Title);

                    foreach (MenuLink link in menu.Links)
                    {

                        if (sArray.Contains(link.Code))
                        {
                            b = true;
                            MYLeftMenu += string.Format("<li><a class='J_menuItem' href={0}>{1}</a></li>", link.Href, link.Title);
                        }

                    }

                }


            }
            if (b)
            {
                MYLeftMenu += " </ul></li>";
            }
        }



    }

    protected void Exit(object sender, EventArgs e)
    {
        Session["AdminNo"] = null;
        Session["AdminName"] = null;
        Session["AdminType"] = null;
        Session["AdminLevel"] = null;
        Utils.WriteCookie("AdminName", "lncms", -1440);
        Utils.WriteCookie("AdminPwd", "lncms", -1440);
        Response.Redirect("login.aspx");
    }



}

